package gr.handmademarket.ui.pages;

import gr.handmademarket.po.enums.SellerTabType;
import gr.handmademarket.po.implementations.Seller;
import gr.handmademarket.ui.WebHandMadeSession;
import gr.handmademarket.ui.tabs.SellerTab;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.extensions.ajax.markup.html.tabs.AjaxTabbedPanel;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

@AuthorizeInstantiation("SELLER")
public class SellerAdminPage 
extends CommonTemplatePage{

	/**
	 * the tabs.
	 */
	private List<ITab> tabs = createTabs(); 
	
	/**
	 * the tabbed panel.
	 */
	@SuppressWarnings({ "nls", "rawtypes", "unchecked" })
	private AjaxTabbedPanel tabbedPanel = new AjaxTabbedPanel("tabbedPanel", tabs);
	
	/**
	 * serialVersionUID.
	 */
	private static final long serialVersionUID = 1L;
	
	public SellerAdminPage() {
		super();
		add(tabbedPanel);
	}
	
	private List<ITab> createTabs(){
		List<ITab> itabs = new ArrayList<ITab>();
		WebHandMadeSession session = (WebHandMadeSession) WebHandMadeSession.get();
		Seller seller = (Seller) session.getUser();
		IModel<Seller> model = new Model<Seller> (seller);
		for (SellerTabType type : SellerTabType.values()){
			SellerTab tab = new SellerTab(model, type);
			itabs.add(tab);
		}
		return itabs;
	}

}
